﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;

public partial class Admin_shop_User_Detail : AdminBase
{
    public string guid = "0", result, result1, sum1, sum2, sum3, myUname;
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.CacheControl = "no-cache";
        if (!string.IsNullOrEmpty(Request.Params["Guid"]))
        {
            guid = HttpContext.Current.Request.QueryString["Guid"];
        }
        if (!IsPostBack)
        {
            grbind();
        }
    }

    private void grbind()
    {

        Entities MyDB = new Entities();

        var mnews = MyDB.Y_Order.Where(x => x.UGUID == guid && x.OState == 0).GroupBy(l => new { spid = l.SPID, Name = l.SPName }).Select(x => new
        {
            SPID = x.Key.spid,
            Name = x.Key.Name,
            ONumber = x.Sum(t => t.ONumber)

        });//全部


        Repeater1.DataSource = mnews.ToList();
        Repeater1.DataBind();


        this.Repeater2.DataSource = MyDB.Y_Order.Where(x => x.UGUID == guid &&x.OParentId == 0).OrderByDescending(x => x.OCreatTime).ToList();//全部
        this.Repeater2.DataBind();



        var _order = MyDB.Y_Order.Where(x => x.UparentId == guid && x.OParentId == 0).OrderByDescending(x => x.OCreatTime);

        this.Repeater3.DataSource = _order.ToList();//已发货（待收货）
        this.Repeater3.DataBind();


        var sorder = MyDB.S_Order.Where(x => x.UGUID == guid && x.OParentId == 0).OrderByDescending(x => x.OCreatTime);//全部
        this.Repeater4.DataSource = sorder.ToList();//2待收货
        this.Repeater4.DataBind();



    }

    protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            int order_id = Convert.ToInt32(((Label)e.Item.FindControl("od_id")).Text);
            Repeater dl = (Repeater)e.Item.FindControl("Repeater22"); //找到DataList1控件
            if (order_id != 0)
            {
                Entities MyDB = new Entities();

                var mnews = MyDB.Y_Order.Where(x => x.OParentId == order_id || x.OrderID == order_id);//全部

                dl.DataSource = mnews.ToList();
                dl.DataBind();
            }
        }
    }


    protected void Repeater3_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            int order_id = Convert.ToInt32(((Label)e.Item.FindControl("od_id")).Text);
            Repeater dl = (Repeater)e.Item.FindControl("Repeater33"); //找到DataList1控件
            if (order_id != 0)
            {
                Entities MyDB = new Entities();

                var mnews = MyDB.Y_Order.Where(x => x.OParentId == order_id || x.OrderID == order_id);//全部

                dl.DataSource = mnews.ToList();
                dl.DataBind();
            }
        }
    }

    protected void Repeater4_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            int order_id = Convert.ToInt32(((Label)e.Item.FindControl("od_id")).Text);
            Repeater dl = (Repeater)e.Item.FindControl("Repeater44"); //找到DataList1控件
            if (order_id != 0)
            {
                Entities MyDB = new Entities();

                var mnews = MyDB.S_Order.Where(x => x.OParentId == order_id || x.OrderID == order_id);//全部

                dl.DataSource = mnews.ToList();
                dl.DataBind();
            }
        }
    }



}